<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" lang="en">
<head th:fragment="login-header">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>商盟惠购商城后台管理</title>
    <link rel="stylesheet" href="${webPath}/styles/bootstrap.min.css">
    <link rel="stylesheet" href="${webPath}/styles/sb-admin-2.css">
    <link rel="stylesheet" href="${webPath}/font-awesome/css/font-awesome.min.css">
    <script src="${webPath}/scripts/jquery.min.js" type="text/javascript"></script>
    <script src="${webPath}/scripts/bootstrap.min.js" type="text/javascript"></script>
    <script src="${webPath}/scripts/sb-admin-2.js" type="text/javascript"></script>
    <script src="${webPath}/scripts/metisMenu.min.js" type="text/javascript"></script>
    <script src="${webPath}/scripts/jquery.cookie.js" type="text/javascript"></script>
</head>

<body>
<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default" style="background:#fff;">
                <div class="panel-heading">
                    <h1 class="panel-title">商盟惠购商城后台管理</h1>
                </div>
                <div class="panel-body">
                    <form role="form">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" id="username" placeholder="请输入登录账号" name="email" type="email"
                                       autofocus>
                            </div>
                            <div class="form-group">
                                <input class="form-control" id="password" placeholder="请输入登录密码" name="password"
                                       type="password" value="">
                            </div>
                            <a href="javascript:void(0);" class="btn btn-lg btn-primary btn-block" onClick="admin_login()">登录</a>
                            <div class="alert alert-danger alert-dismissible login-alert" role="alert">
                                <button type="button" class="close button4-alert" aria-hidden="true"
                                        data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                                <strong id="login-return"></strong>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    $(function () {
        $('.login-alert').hide();
    });
    
    function admin_login() {
        var baseURL = "${webPath}/login/tologin";
        var json_package = {
            "head": {},
            "body": {
                "username": $("#username").val(),
                "password": $("#password").val()
            }
        }
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '1') {
                $('.login-alert').show();
                $("#login-return").text(result.body.description)
            } else {
                $('.login-alert').hide();
                $.cookie('name', result.body.name, {path: '/'});
                $.cookie('is_login', result.body.is_login, {path: '/'})
                location.href = "${webPath}/toOrder/hdnksdftu123bzz";
            }
        })
    }
    
    //设置按键盘的enter键进行登陆
    $(function(){
    	$(document).keydown(function(e){
    		if (!e){
    		   e = window.event;  
    		}  
    		if ((e.keyCode || e.which) == 13) {  
    			admin_login();//按键盘的enter键进行登陆 
    		}
    	});
    });
</script>
</body>

</html>
